// const { notEmpty } = require('../utils.js');
const chalk = require('chalk')

module.exports = {
    description: '欢迎进入模块新增系统，请根据提示完成操作',
    prompts: [
        {
            type: 'input',
            name: 'name',
            message: '请输入工程名称：'
        },
        {
            type: 'confirm',
            name: 'blocks',
            message: '是否需要生成项目公共头？',
            default: false
        },
        {
            type: 'confirm',
            name: 'vant',
            message: '是否使用VantUI组件？',
            default: false
        },
        {
            type: 'input',
            name: 'proxy',
            message: '请输入后端地址：'
        },
        {
            type: 'input',
            name: 'port',
            message: '请输入前端运行端口（例如：8080）：'
        }
    ],
    actions: data => {
        const name = '{{properCase name}}';
        const isHeader = data.blocks ? 'plop-templates/pro-demo/components/header/header.hbs' : '';
        const actions = [
            {
                type: 'add',
                path: 'src/{{name}}/api/httpCore.js',
                templateFile: 'plop-templates/pro-demo/api/httpCore.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/assets/pub-pic/logo.png',
                templateFile: 'plop-templates/pro-demo/assets/pub-pic/logo.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/assets/pub-ui/communication/homepage/css/index.css',
                templateFile: 'plop-templates/pro-demo/assets/pub-ui/communication/homepage/css/index.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/assets/pub-ui/communication/homepage/img/logo.png',
                templateFile: 'plop-templates/pro-demo/assets/pub-ui/communication/homepage/img/logo.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/assets/pub-ui/css/header.css',
                templateFile: 'plop-templates/pro-demo/assets/pub-ui/css/header.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/assets/pub-ui/js/rem.js',
                templateFile: 'plop-templates/pro-demo/assets/pub-ui/js/rem.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/common/comMix.js',
                templateFile: 'plop-templates/pro-demo/common/comMix.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/common/permission.js',
                templateFile: 'plop-templates/pro-demo/common/permission.hbs',
                data: {
                    vant: data.vant
                }
            },
            {
                type: 'add',
                path: 'src/{{name}}/components/footer/index.vue',
                templateFile: 'plop-templates/pro-demo/components/footer/index.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/components/header/header.vue',
                templateFile: isHeader
            },
            {
                type: 'add',
                path: 'src/{{name}}/page/communication/README.md',
                templateFile: 'plop-templates/pro-demo/page/communication/README.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/page/home/Home.vue',
                templateFile: 'plop-templates/pro-demo/page/home/Home.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/router/index.js',
                templateFile: 'plop-templates/pro-demo/router/index.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/store/modules/user.js',
                templateFile: 'plop-templates/pro-demo/store/modules/user.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/store/getters.js',
                templateFile: 'plop-templates/pro-demo/store/getters.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/store/index.js',
                templateFile: 'plop-templates/pro-demo/store/index.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/util/cookieMethod.js',
                templateFile: 'plop-templates/pro-demo/util/cookieMethod.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/util/takeFontSize.js',
                templateFile: 'plop-templates/pro-demo/util/takeFontSize.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/App.vue',
                templateFile: 'plop-templates/pro-demo/App.hbs'
            },
            {
                type: 'add',
                path: 'src/{{name}}/main.js',
                templateFile: 'plop-templates/pro-demo/main.hbs'
            },
            {
                type: 'add',
                path: 'static/static{{name}}/logo.png',
                templateFile: 'plop-templates/pro-demo/static/logo.hbs'
            },
            {
                type: 'append',
                path: 'package.json',
                templateFile: 'plop-templates/pro-demo/package/package.hbs',
                pattern: /\"dev\": \"webpack-dev-server --inline --progress --config build\/webpack\.dev\.conf\.js\",/,
                data: {
                    name: data.name
                }
            },
            {
                type: 'append',
                path: 'config/vmp.conf.js',
                templateFile: 'plop-templates/pro-demo/config/index.hbs',
                pattern: /\/\/\*boundary/,
                data: {
                    name: data.name,
                    static: 'static' + data.name,
                    proxyTableKey: '/h/'+ data.name +'/rest',
                    target: data.proxy,
                    port: data.port,
                },
                skip: function() {
                    setTimeout(() => {
                        console.log(chalk.cyan('\n  文件生成成功...您还需要以下几步来完成配置:ヽ(￣▽￣)ﾉ\n'))
                        console.log(chalk.yellow(
                            '  (1)打包成功后请在生产Nginx的location中加入反向代理。\n'+
                            '  (2)我们为您在config/vmp.conf.js中加入反向代理逻辑。'
                        ))
                    }, 500);
                }
            }
        ];
        return actions;
    }
};
  